package february.test_2_29;

import java.util.Scanner;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String tmp = scanner.nextLine();
        int[] hash = new int[200];
        for(int i = 0; i < str.length(); i++) {
            hash[str.charAt(i)]++;
        }
        if(('a' <= tmp.charAt(0) && tmp.charAt(0) <= 'z') || ('A' <= tmp.charAt(0) && tmp.charAt(0) <= 'Z')) {
            System.out.println(hash[tmp.toUpperCase().charAt(0)] + hash[tmp.toLowerCase().charAt(0)]);
        } else {
            System.out.println(hash[tmp.charAt(0)]);
        }

    }
}
